package com.lagou.minicat.core;

import org.dom4j.Document;
import org.dom4j.Element;

import java.util.ArrayList;
import java.util.List;

public class Engine {

    private List<Host> hosts = new ArrayList<>();

    public void init(Document serverConfigDoc) {
        Element rootElement = serverConfigDoc.getRootElement();
        List<Element> hostNodes = rootElement.selectNodes("/Server/Service/Engine/Host");
        hostNodes.forEach(n -> {
            String name = n.attributeValue("name");
            String appBase = n.attributeValue("appBase");
            Host host = new Host(name, appBase);
            host.init(serverConfigDoc);
            hosts.add(host);
        });
    }

    public List<Host> getHosts() {
        return hosts;
    }

    public void setHosts(List<Host> hosts) {
        this.hosts = hosts;
    }
}
